home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWRefCnt / Include / FWSOMPtr.tpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  6.4 KB  |  236 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSOMPtr.tpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSOMPTR_H
  11. #include "FWSOMPtr.h"
  12. #endif
  13.  
  14. #ifndef FWSOMENV_H
  15. #include "FWSOMEnv.h"
  16. #endif
  17.  
  18.  
  19. //----------------------------------------------------------------------------------------
  20. //    FW_TSOMPtr<TRep>::FW_TSOMPtr
  21. //----------------------------------------------------------------------------------------
  22.  
  23. template<class TRep>
  24. FW_TSOMPtr<TRep>::FW_TSOMPtr() :
  25.     fRep(NULL)
  26. {
  27.     FW_END_CONSTRUCTOR
  28. }
  29.  
  30. //----------------------------------------------------------------------------------------
  31. //    FW_TSOMPtr<TRep>::~FW_TSOMPtr
  32. //----------------------------------------------------------------------------------------
  33.  
  34. template<class TRep>
  35. FW_TSOMPtr<TRep>::~FW_TSOMPtr()
  36. {
  37.     FW_START_DESTRUCTOR
  38.     delete fRep;
  39. }
  40.  
  41. //----------------------------------------------------------------------------------------
  42. //    FW_TSOMPtr<TRep>::FW_TSOMPtr
  43. //----------------------------------------------------------------------------------------
  44.  
  45. template<class TRep>
  46. FW_TSOMPtr<TRep>::FW_TSOMPtr(Environment *ev, TRep* other) :
  47.     fRep(NULL)
  48. {
  49.     SetRep(ev, other);
  50.     FW_END_CONSTRUCTOR
  51. }
  52.  
  53. //----------------------------------------------------------------------------------------
  54. //    FW_TSOMPtr<TRep>::SetRep
  55. //----------------------------------------------------------------------------------------
  56.  
  57. template<class TRep>
  58. void FW_TSOMPtr<TRep>::SetRep(Environment *, TRep* rep)
  59. {
  60.     if (fRep != rep)
  61.     {
  62.         delete fRep;
  63.         fRep = rep;
  64.     }
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. //    FW_TSOMPtr<TRep>::operator new
  69. //----------------------------------------------------------------------------------------
  70.  
  71. // [JEL]
  72. // This method is private, and I'd prefer to leave it undefined, but CodeWarrior seems
  73. // to complain when instantiating templates with undefined methods, even if the methods
  74. // aren't used.
  75.  
  76. #if __MWERKS__ < 0x0800
  77.  
  78. template<class TRep>
  79. void* FW_TSOMPtr<TRep>::operator new(size_t size)
  80. {
  81.     FW_PRIV_ASSERT(false);
  82.     return 0;
  83. }
  84.  
  85. #endif
  86.  
  87. //----------------------------------------------------------------------------------------
  88. //    FW_TSOMPtr<TRep>::FW_TSOMPtr(const FW_TSOMPtr<TRep>& other)
  89. //----------------------------------------------------------------------------------------
  90.  
  91. template<class TRep>
  92. FW_TSOMPtr<TRep>::FW_TSOMPtr(const FW_TSOMPtr<TRep>&)
  93. {
  94.     // [jkp] MetroWerks wants this to be defined
  95.     FW_PRIV_ASSERT(false);
  96. }
  97.  
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    FW_TSOMPtr<TRep>::operator=(const FW_TSOMPtr<TRep>& other)
  101. //----------------------------------------------------------------------------------------
  102.  
  103. template<class TRep>
  104. void FW_TSOMPtr<TRep>::operator=(const FW_TSOMPtr<TRep>&)
  105. {
  106.     // [jkp] MetroWerks wants this to be defined
  107.     FW_PRIV_ASSERT(false);
  108. }
  109.  
  110.  
  111.  
  112. //----------------------------------------------------------------------------------------
  113. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  114. //----------------------------------------------------------------------------------------
  115.  
  116. template<class TRep>
  117. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr() :
  118.     fRep(NULL)
  119. {
  120.     FW_END_CONSTRUCTOR
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_TCountedSOMPtr<TRep>::~FW_TCountedSOMPtr
  125. //----------------------------------------------------------------------------------------
  126.  
  127. template<class TRep>
  128. FW_TCountedSOMPtr<TRep>::~FW_TCountedSOMPtr()
  129. {
  130.     FW_START_DESTRUCTOR
  131.     if (fRep != NULL)
  132.     {
  133.         FW_SOMEnvironment ev;
  134.  
  135.         if (fRep->Release(ev) == 0)
  136.             delete fRep;
  137.     }
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  142. //----------------------------------------------------------------------------------------
  143.  
  144. template<class TRep>
  145. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr(const FW_TCountedSOMPtr<TRep>& other) :
  146.     fRep(other.fRep)
  147. {
  148.     if (fRep != NULL)
  149.     {
  150.         FW_SOMEnvironment ev;
  151.  
  152.         fRep->Acquire(ev);
  153.     }
  154.  
  155.     FW_END_CONSTRUCTOR
  156. }
  157.  
  158. //----------------------------------------------------------------------------------------
  159. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  160. //----------------------------------------------------------------------------------------
  161.  
  162. template<class TRep>
  163. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr(Environment *ev, const FW_TCountedSOMPtr<TRep>& other) :
  164.     fRep(other.fRep)
  165. {
  166.     if (fRep != NULL)
  167.         fRep->Acquire(ev);
  168.  
  169.     FW_END_CONSTRUCTOR
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr
  174. //----------------------------------------------------------------------------------------
  175.  
  176. template<class TRep>
  177. FW_TCountedSOMPtr<TRep>::FW_TCountedSOMPtr(Environment *ev, TRep* other) :
  178.     fRep(other)
  179. {
  180.     if (fRep != NULL)
  181.         fRep->Acquire(ev);
  182.  
  183.     FW_END_CONSTRUCTOR
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_TCountedSOMPtr<TRep>::operator=
  188. //----------------------------------------------------------------------------------------
  189.  
  190. template<class TRep>
  191. void FW_TCountedSOMPtr<TRep>::operator=(TRep* rep)
  192. {
  193.     FW_SOMEnvironment ev;
  194.     SetRep(ev, rep);
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    FW_TCountedSOMPtr<TRep>::SetRep
  199. //----------------------------------------------------------------------------------------
  200.  
  201. template<class TRep>
  202. void FW_TCountedSOMPtr<TRep>::SetRep(Environment *ev, TRep* rep)
  203. {
  204.     if (fRep != rep)
  205.     {
  206.         if (fRep != NULL && fRep->Release(ev) == 0)
  207.             delete fRep;
  208.  
  209.         fRep = rep;
  210.         
  211.         if (fRep != NULL)
  212.             fRep->Acquire(ev);
  213.     }
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //    FW_TCountedSOMPtr<TRep>::operator new
  218. //----------------------------------------------------------------------------------------
  219.  
  220. // [JEL]
  221. // This method is private, and I'd prefer to leave it undefined, but CodeWarrior seems
  222. // to complain when instantiating templates with undefined methods, even if the methods
  223. // aren't used.
  224.  
  225. #if __MWERKS__ < 0x0800
  226.  
  227. template<class TRep>
  228. void* FW_TCountedSOMPtr<TRep>::operator new(size_t size)
  229. {
  230.     FW_PRIV_ASSERT(false);
  231.     return 0;
  232. }
  233.  
  234. #endif 
  235.  
  236.